package org.geektimes.projects.user.jmx;

import org.geektimes.projects.user.jmx.mbean.Test;
import org.geektimes.projects.user.jmx.mbean.TestMBean;
import org.geektimes.projects.user.jmx.mbean.User;

import javax.management.*;
import java.lang.management.ManagementFactory;

/**
 * @author tom
 * @since 2021/3/14 13:28
 */
public class JmxAgent {

    public static void init() throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName testMBean = new ObjectName(TestMBean.class.getName()+":type=user");
        mbs.registerMBean(new Test(new User()), testMBean);
    }
}
